﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CultuRAM.Models;


namespace CultuRAM.DAL
{
    public class UnitOfWork : IDisposable
    {
        private readonly CultuRAMContext _context = new CultuRAMContext();

        private GenericRepository<UserProfile> _userProfileRepository;
        private GenericRepository<webpages_UsersInRoles> _usersInRolesRepository;
        private GenericRepository<webpages_Roles> _rolesRepository;
        private GenericRepository<Event> _eventRepository;
        private GenericRepository<EventParticipant> _eventParticipantRepository;
        private GenericRepository<EventProperty> _eventPropertyRepository;
        private GenericRepository<EventPropertyValue> _eventPropertyValueRepository;
        private GenericRepository<EventType> _eventTypeRepository;       
        private GenericRepository<Participant> _participantRepository;
        private GenericRepository<ParticipantType> _participantTypeRepository;
        private GenericRepository<Place> _placeRepository;
        private GenericRepository<Resource> _resourceRepository;
        private GenericRepository<ResourceType> _resourceTypeRepository;
        private GenericRepository<Session> _sessionRepository;
        private GenericRepository<Comment> _commentRepository;
        private GenericRepository<Entity> _entityRepository;
        private GenericRepository<EntityType> _entityTypeRepository;
        private GenericRepository<City> _cityRepository;
        private GenericRepository<AccreditingRequest> _accRequestRepository;
        private GenericRepository<AccreditingState> _accStateRepository;
        private GenericRepository<EventState> _eventStateRepository;
        private GenericRepository<Parameter> _parameterRepository;
        private GenericRepository<Target> _targetRepository;
        private GenericRepository<Alert> _alertRepository;

        //Repository: User Profile
        public GenericRepository<UserProfile> UserProfileRepository
        {
            get
            {
                if (this._userProfileRepository == null)
                {
                    this._userProfileRepository = new GenericRepository<UserProfile>(_context);
                }
                return _userProfileRepository;
            }
        }

        //Repository: User in Roles
        public GenericRepository<webpages_UsersInRoles> UserInRolesRepository
        {
            get
            {
                if (this._usersInRolesRepository == null)
                {
                    this._usersInRolesRepository = new GenericRepository<webpages_UsersInRoles>(_context);
                }
                return _usersInRolesRepository;
            }
        }

        //Repository: Roles
        public GenericRepository<webpages_Roles> RolesRepository
        {
            get
            {
                if (this._rolesRepository == null)
                {
                    this._rolesRepository = new GenericRepository<webpages_Roles>(_context);
                }
                return _rolesRepository;
            }
        }

        //Repository: Event
        public GenericRepository<Event> EventRepository
        {
            get
            {
                if (this._eventRepository == null)
                {
                    this._eventRepository = new GenericRepository<Event>(_context);
                }
                return _eventRepository;
            }
        }

        //Repository: EventParticipant
        public GenericRepository<EventParticipant> EventParticipantRepository
        {
            get
            {
                if (this._eventParticipantRepository == null)
                {
                    this._eventParticipantRepository = new GenericRepository<EventParticipant>(_context);
                }
                return _eventParticipantRepository;
            }
        }

        //Repository: EventProperty
        public GenericRepository<EventProperty> EventPropertyRepository
        {
            get
            {
                if (this._eventPropertyRepository == null)
                {
                    this._eventPropertyRepository = new GenericRepository<EventProperty>(_context);
                }
                return _eventPropertyRepository;
            }
        }

        //Repository: EventPropertyValue
        public GenericRepository<EventPropertyValue> EventPropertyValueRepository
        {
            get
            {
                if (this._eventPropertyValueRepository == null)
                {
                    this._eventPropertyValueRepository = new GenericRepository<EventPropertyValue>(_context);
                }
                return _eventPropertyValueRepository;
            }
        }

        //Repository: EventType
        public GenericRepository<EventType> EventTypeRepository
        {
            get
            {
                if (this._eventTypeRepository == null)
                {
                    this._eventTypeRepository = new GenericRepository<EventType>(_context);
                }
                return _eventTypeRepository;
            }
        }

        //Repository: Participant
        public GenericRepository<Participant> ParticipantRepository
        {
            get
            {
                if (this._participantRepository == null)
                {
                    this._participantRepository = new GenericRepository<Participant>(_context);
                }
                return _participantRepository;
            }
        }

        //Repository: ParticipantType
        public GenericRepository<ParticipantType> ParticipantTypeRepository
        {
            get
            {
                if (this._participantTypeRepository == null)
                {
                    this._participantTypeRepository = new GenericRepository<ParticipantType>(_context);
                }
                return _participantTypeRepository;
            }
        }

        //Repository: Palce
        public GenericRepository<Place> PlaceRepository
        {
            get
            {
                if (this._placeRepository == null)
                {
                    this._placeRepository = new GenericRepository<Place>(_context);
                }
                return _placeRepository;
            }
        }

        //Repository: Resource
        public GenericRepository<Resource> ResourceRepository
        {
            get
            {
                if (this._resourceRepository == null)
                {
                    this._resourceRepository = new GenericRepository<Resource>(_context);
                }
                return _resourceRepository;
            }
        }

        //Repository: ResourceType
        public GenericRepository<ResourceType> ResourceTypeRepository
        {
            get
            {
                if (this._resourceTypeRepository == null)
                {
                    this._resourceTypeRepository = new GenericRepository<ResourceType>(_context);
                }
                return _resourceTypeRepository;
            }
        }

        //Repository: Session
        public GenericRepository<Session> SessionRepository
        {
            get
            {
                if (this._sessionRepository == null)
                {
                    this._sessionRepository = new GenericRepository<Session>(_context);
                }
                return _sessionRepository;
            }
        }

        //Repository: Comment
        public GenericRepository<Comment> CommentRepository
        {
            get
            {
                if (this._commentRepository == null)
                {
                    this._commentRepository = new GenericRepository<Comment>(_context);
                }
                return _commentRepository;
            }
        }

        //Repository: Entity
        public GenericRepository<Entity> EntityRepository
        {
            get
            {
                if (this._entityRepository == null)
                {
                    this._entityRepository = new GenericRepository<Entity>(_context);
                }
                return _entityRepository;
            }
        }

        //Repository: Entity Type
        public GenericRepository<EntityType> EntityTypeRepository
        {
            get
            {
                if (this._entityTypeRepository == null)
                {
                    this._entityTypeRepository = new GenericRepository<EntityType>(_context);
                }
                return _entityTypeRepository;
            }
        }

        //Repository: City
        public GenericRepository<City> CityRepository
        {
            get
            {
                if (this._cityRepository == null)
                {
                    this._cityRepository = new GenericRepository<City>(_context);
                }
                return _cityRepository;
            }
        }

        //Repository: Accrediting Request
        public GenericRepository<AccreditingRequest> AccResquestRepository
        {
            get
            {
                if (this._accRequestRepository == null)
                {
                    this._accRequestRepository = new GenericRepository<AccreditingRequest>(_context);
                }
                return _accRequestRepository;
            }
        }

        //Repository: Accrediting State
        public GenericRepository<AccreditingState> AccStateRepository
        {
            get
            {
                if (this._accStateRepository == null)
                {
                    this._accStateRepository = new GenericRepository<AccreditingState>(_context);
                }
                return _accStateRepository;
            }
        }

        //Repository: Event State
        public GenericRepository<EventState> EventStateRepository
        {
            get
            {
                if (this._eventStateRepository == null)
                {
                    this._eventStateRepository = new GenericRepository<EventState>(_context);
                }
                return _eventStateRepository;
            }
        }

        //Repository: Parameter
        public GenericRepository<Parameter> ParameterRepository
        {
            get
            {
                if (this._parameterRepository == null)
                {
                    this._parameterRepository = new GenericRepository<Parameter>(_context);
                }
                return _parameterRepository;
            }
        }

        //Repository: Target
        public GenericRepository<Target> TargetRepository
        {
            get
            {
                if (this._targetRepository == null)
                {
                    this._targetRepository = new GenericRepository<Target>(_context);
                }
                return _targetRepository;
            }
        }

        //Repository: Alert
        public GenericRepository<Alert> AlertRepository
        {
            get
            {
                if (this._alertRepository == null)
                {
                    this._alertRepository = new GenericRepository<Alert>(_context);
                }
                return _alertRepository;
            }
        }



        //SAVE AND DISPOSED METHODS 
        public void Save()
        {
            _context.SaveChanges();
        }

        private bool _disposed = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!this._disposed)
            {
                if (disposing)
                {
                    _context.Dispose();
                }
            }
            this._disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}